//
//  GMHomeVC.m
//  Teecloud
//
//  Created by 小熊 on 2018/5/23.
//  Copyright © 2018年 小熊. All rights reserved.
//

#import "GMHomeVC.h"
#import <AVFoundation/AVFoundation.h>
#import "QRCodeScanningVC.h"
#import "GMHomeHeadView.h"
#import "GMStudyVC.h"
#import "GMGroupVC.h"
#import "GMRankVC.h"
#import "GMHomeBaseModel.h"
#import "GMBuyVideoVC.h"
#import "XZNewsCaseVC.h"
#import "GMBuyFile.h"
#import "GMReadPDFVC.h"
#import "GMExaminationVC.h"
#import "GMCoursePackageVC.h"
#import "XZMyGroupDetailVC.h"
#import "XZGroupIntroduceVC.h"
#import "GMPlayerViewController.h"
#import "WMPanGestureRecognizer.h"

#import "GMMyClassVC.h"
#import "XZMyMessageVC.h"
#import "XZMyQuestionVC.h"
#import "XZMyExamVC.h"
#import "XZMyGroupVC.h"
#import "GMExercisesVC.h"
#import "GMBaseNavigationController.h"
static CGFloat const kWMMenuViewHeight = 35.0; //标题视图高度
@interface GMHomeVC ()<PYSearchViewControllerDelegate,SFSafariViewControllerDelegate>
@property (nonatomic, strong) NSArray *musicCategories;
@property (nonatomic, strong) GMHomeHeadView *headerView;
@property (nonatomic, strong) WMPanGestureRecognizer *panGesture;
@property (nonatomic, assign) CGPoint lastPoint;
/**用来判断点击的是课件还是班组*/
@property (nonatomic, copy) NSString *tempStr;
//第一次进来就加载菊花 后面的不管
@property (nonatomic, assign) BOOL isFirst;

@property (nonatomic, strong) UILabel *groupCount;
@property (nonatomic, strong) UILabel *rankCount;
@end

@implementation GMHomeVC
- (UILabel *)groupCount{
    if (!_groupCount) {
        _groupCount = [[UILabel alloc]initWithFrame:CGRectMake(70, 0, 20, 20)];
        _groupCount.font = [UIFont systemFontOfSize:10.0f];
        _groupCount.backgroundColor = kRedColor;
        _groupCount.textColor= kWhiteColor;
        _groupCount.textAlignment = NSTextAlignmentCenter;
        _groupCount.text = @"99+";
        _groupCount.layer.cornerRadius = 10.0f;
        _groupCount.clipsToBounds = true;
    }
    return _groupCount;
}
- (UILabel *)rankCount{
    if (!_rankCount) {
         _rankCount = [[UILabel alloc]initWithFrame:CGRectMake(70, 0, 20, 20)];
        _rankCount.font = [UIFont systemFontOfSize:10.0f];
        _rankCount.backgroundColor = kRedColor;
        _rankCount.textColor= kWhiteColor;
        _rankCount.textAlignment = NSTextAlignmentCenter;
        _rankCount.text = @"20";
        _rankCount.layer.cornerRadius = 10.0f;
        _rankCount.clipsToBounds = true;
    }
    return _rankCount;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getHomeData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"腾云教育";
    [self addRightBarButtonWithFirstImage:[UIImage imageNamed:@"icon-NAV-scanner-"] action:@selector(sweepClick)];
    //导航栏logo
    UIImageView *img = [[UIImageView alloc]init];
    img.image = [[UIImage imageNamed:@"navIcon"]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    UIBarButtonItem *leftBar = [[UIBarButtonItem alloc]initWithCustomView:img];
    self.navigationItem.leftBarButtonItem = leftBar;
    [self.view addSubview:self.headerView];
    self.panGesture = [[WMPanGestureRecognizer alloc] initWithTarget:self action:@selector(panOnView:)];
    [self.view addGestureRecognizer:self.panGesture];
}

-(GMHomeHeadView *)headerView{
    if (!_headerView) {
        _headerView = [GMHomeHeadView viewFromXib];
        _headerView.frame = CGRectMake(0, 0, DEVICE_WIDTH, kWMHeaderViewHeight);
        kWeakObject(self)
        /**防止循环引用*/
        _headerView.clickBlock = ^(NSString *typeStr) {
            [weakself handleClickWithTypeStr:typeStr];
        };
        //轮播的跳转
        _headerView.homeBannerBlock = ^(GMTopModel *model) {
            [weakself skipBanner:model];
        };
    }
    return _headerView;
}
- (instancetype)init {
    if (self = [super init]) {
        self.titleSizeNormal = 12;
        self.titleSizeSelected = 12;
        self.menuViewStyle = WMMenuViewStyleDefault;
        self.menuViewLayoutMode = WMMenuViewLayoutModeLeft;
        self.menuItemWidth = 90;
        self.titleColorSelected = kWhiteColor;
        self.titleColorNormal = k333333Color;
        self.viewTop = kNavigationBarHeight + kWMHeaderViewHeight;
        self.scrollEnable = NO;
        //下划线
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 33, kScreenWidth, 2)];
        line.backgroundColor = k0065EAColor;
        [self.menuView addSubview:line];
    }
    return self;
}
- (void)getHomeData{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:FROM_IOS forKey:@"from"];
    [dict setValue:[XGMArchiverTools cacheForKey:BUSIORGID] forKey:@"busiOrgId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_UserId] forKey:@"userId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_identifierNumber] forKey:@"loginFinger"];
    [dict setValue:[XGMArchiverTools cacheForKey:@"lastGetTime"] forKey:@"lastGetTime"];
    //第一次加载菊花
    if (!self.isFirst) {
        self.isFirst = YES;
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    }
    [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=GetHomeInfo&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyNetworkElseCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                GMHomeBaseModel *baseModel = [GMHomeBaseModel mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                NSInteger newMsg = [baseModel.MyCounts.MyNewMsgCount integerValue];
                NSInteger lastMsg = [[XGMArchiverTools cacheForKey:@"myNewMsgCount"] integerValue];
                NSInteger finaMsg = newMsg + lastMsg;
                [XGMArchiverTools cache:@(finaMsg) ForKey:@"myNewMsgCount"];
                /**存储上一次拉取数据的时间*/
                [XGMArchiverTools cache:[responseObject objectForKey:RESULT_NAME_Message] ForKey:@"lastGetTime"];
                self.headerView.baseModel = baseModel;
                //把值传给GMStudyVC控制器
                [[NSNotificationCenter defaultCenter] postNotificationName:@"postStudyRes" object:baseModel.StudyRes];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"请求出错" toView:self.view];
        }
    }];
}
- (void)panOnView:(WMPanGestureRecognizer *)recognizer {

    CGPoint currentPoint = [recognizer locationInView:self.view];
    
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        self.lastPoint = currentPoint;
    } else if (recognizer.state == UIGestureRecognizerStateEnded) {
        
        CGPoint velocity = [recognizer velocityInView:self.view];
        CGFloat targetPoint = velocity.y < 0 ? kNavigationBarHeight : kNavigationBarHeight + kWMHeaderViewHeight;
        NSTimeInterval duration = fabs((targetPoint - self.viewTop) / velocity.y);
        
        if (fabs(velocity.y) * 1.0 > fabs(targetPoint - self.viewTop)) {
            [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
                self.viewTop = targetPoint;
            } completion:nil];
            
            return;
        }
        
    }
    CGFloat yChange = currentPoint.y - self.lastPoint.y;
    
    self.viewTop += yChange;
    self.lastPoint = currentPoint;
}
// MARK: ChangeViewFrame (Animatable)
- (void)setViewTop:(CGFloat)viewTop {
    _viewTop = viewTop;
    
    if (_viewTop <= kNavigationBarHeight) {
        _viewTop = kNavigationBarHeight;
    }
    
    if (_viewTop > kWMHeaderViewHeight + kNavigationBarHeight) {
        _viewTop = kWMHeaderViewHeight + kNavigationBarHeight;
    }
    
    self.headerView.frame = ({
        CGRect oriFrame = self.headerView.frame;
        oriFrame.origin.y = _viewTop - kWMHeaderViewHeight;
        oriFrame;
    });
    
    [self forceLayoutSubviews];
}

- (void)sweepClick{
    // 1、 获取摄像设备
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (device) {
        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (status == AVAuthorizationStatusNotDetermined) {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                if (granted) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        QRCodeScanningVC *vc = [[QRCodeScanningVC alloc] init];
                        [self.navigationController pushViewController:vc animated:YES];
                    });
                    
                    SGQRCodeLog(@"当前线程 - - %@", [NSThread currentThread]);
                    // 用户第一次同意了访问相机权限
                    SGQRCodeLog(@"用户第一次同意了访问相机权限");
                    
                } else {
                    
                    // 用户第一次拒绝了访问相机权限
                    SGQRCodeLog(@"用户第一次拒绝了访问相机权限");
                }
            }];
        } else if (status == AVAuthorizationStatusAuthorized) { // 用户允许当前应用访问相机
            QRCodeScanningVC *vc = [[QRCodeScanningVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        } else if (status == AVAuthorizationStatusDenied) { // 用户拒绝当前应用访问相机
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"⚠️ 警告" message:@"请去-> [设置 - 隐私 - 相机 - SGQRCodeExample] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
            UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            
            [alertC addAction:alertA];
            [self presentViewController:alertC animated:YES completion:nil];
            
        } else if (status == AVAuthorizationStatusRestricted) {
            NSLog(@"因为系统原因, 无法访问相册");
        }
    } else {
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertC addAction:alertA];
        [self presentViewController:alertC animated:YES completion:nil];
    }
    
}
#pragma mark - Datasource & Delegate
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.musicCategories.count;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    
    switch (index) {
        case 0:
            return [[GMStudyVC alloc] init];
        case 1:{
            return [[GMGroupVC alloc] init];
        }
        default:
            return [[GMRankVC alloc] init];
    }
}

/**
 切换到排行榜隐藏搜索按钮
 切换不同的模块修改其WMMenuItem的背景颜色

 @param pageController pageController
 @param viewController viewController
 @param info info（index title）
 */
- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    if ([info[@"title"] isEqualToString:@"排行榜"]) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
        pageController.menuView.rightView = view;
    }else {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"search-blue-64"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];
        btn.frame = CGRectMake(0,0, kWMMenuViewHeight, kWMMenuViewHeight);
        self.menuView.rightView = btn;
    }
   
    if ([info[@"title"] isEqualToString:@"学习课件"]) {
        self.tempStr =@"学习课件";
        WMMenuItem *item1 = [pageController.menuView itemAtIndex:0];
        item1.backgroundColor = k0065EAColor;
        WMMenuItem *item2 = [pageController.menuView itemAtIndex:1];
        item2.backgroundColor = kWhiteColor;
        WMMenuItem *item3 = [pageController.menuView itemAtIndex:2];
        item3.backgroundColor = kWhiteColor;
        dispatch_async(dispatch_get_main_queue(), ^{
            [item2 addSubview:self.groupCount];
            [item3 addSubview:self.rankCount];
        });
    }else if ([info[@"title"] isEqualToString:@"班组社团"]){
        self.tempStr =@"班组社团";
        WMMenuItem *item1 = [pageController.menuView itemAtIndex:0];
        item1.backgroundColor = kWhiteColor;
        WMMenuItem *item2 = [pageController.menuView itemAtIndex:1];
        item2.backgroundColor = k0065EAColor;
        WMMenuItem *item3 = [pageController.menuView itemAtIndex:2];
        item3.backgroundColor = kWhiteColor;
        
        [item2 addSubview:self.groupCount];
        [item3 addSubview:self.rankCount];
    }else{//排行榜
        WMMenuItem *item1 = [pageController.menuView itemAtIndex:0];
        item1.backgroundColor = kWhiteColor;
        WMMenuItem *item2 = [pageController.menuView itemAtIndex:1];
        item2.backgroundColor = kWhiteColor;
        WMMenuItem *item3 = [pageController.menuView itemAtIndex:2];
        item3.backgroundColor = k0065EAColor;
        [item2 addSubview:self.groupCount];
        [item3 addSubview:self.rankCount];
    }
}
- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.musicCategories[index];
}
- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, _viewTop, self.view.frame.size.width, kWMMenuViewHeight);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    CGFloat originY = _viewTop + kWMMenuViewHeight;
    return CGRectMake(0, originY, self.view.frame.size.width, self.view.frame.size.height - originY);
}

#pragma mark - lazy
- (NSArray *)musicCategories {
    if (!_musicCategories) {
        _musicCategories = @[@"学习课件", @"班组社团", @"排行榜"];
    }
    return _musicCategories;
}
-(void)searchBtnClick{
    PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:nil searchBarPlaceholder:@"输入关键词" didSearchBlock:^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
        [self dismissViewControllerAnimated:YES completion:^{
            if ([self.tempStr isEqualToString:@"学习课件"]) {
                GMStudyVC *classVC =[[GMStudyVC alloc] init];
                classVC.searchText = searchText;
                [self.navigationController pushViewController:classVC animated:YES];
            }else{
                GMGroupVC *group = [[GMGroupVC alloc] init];
                group.searchText = searchText;
                [self.navigationController pushViewController:group animated:YES];
            }
        }];
    }];
    searchViewController.searchTextField.textColor = [UIColor colorWithHexString:@"101010" andAlpha:1.0];
    searchViewController.searchTextField.tintColor = [UIColor colorWithHexString:@"101010" andAlpha:1.0];
    searchViewController.searchTextField.font = [UIFont systemFontOfSize:10.0f];
    searchViewController.searchBar.layer.cornerRadius = 16;
    searchViewController.searchBar.clipsToBounds = YES;
    searchViewController.searchBar.layer.borderWidth = 0.5;
    searchViewController.searchBar.layer.borderColor = [UIColor colorWithHexString:@"D7D7D7" andAlpha:1.0].CGColor;
    [searchViewController.cancelButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
    searchViewController.cancelButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    
    searchViewController.delegate = self;
    searchViewController.hotSearchStyle = PYHotSearchStyleDefault;
    searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag;
    GMBaseNavigationController *base = [[GMBaseNavigationController alloc]initWithRootViewController:searchViewController];
    [self presentViewController:base animated:YES completion:nil];
}
#pragma mark - SFSafariViewControllerDelegate -
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller{
    XZLog(@"击done");
}
/**
 点击轮播的跳转

 @param model 轮播的模型
 */
- (void)skipBanner:(GMTopModel *)model{
    [self updateReadCount:model.AdId];
    [self bannerSkipControllerWithNewsBanner:model];
}
/*
 *更新广告阅读计数
 */
-(void)updateReadCount:(NSString *)addId{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:FROM_IOS forKey:@"from"];
    [dict setValue:[XGMArchiverTools cacheForKey:BUSIORGID] forKey:@"busiOrgId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_UserId] forKey:@"userId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_identifierNumber] forKey:@"loginFinger"];
    //广告Id
    [dict setValue:addId forKey:@"adId"];
    
    [HJNetwork POSTWithURL:[NSString stringWithFormat:@"/ajax-api.ashx?$c=TeeyunApp&$m=UpdateAdCount&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                XZLog(@"计数成功");
            }else{
                XZLog(@"计数失败");
            }
            
        }else{
            XZLog(@"%@",error);
        }
    }];
}
/*************************************轮播跳转******************************/
/**
 根据模型中RelType来进行跳转
 轮播
 @param model XZBannerTops
 */
- (void)bannerSkipControllerWithNewsBanner:(GMTopModel *)model{
    if (1 == [model.RelType integerValue]) {//model.RelType=1
        [self bannerSkipRelTypeIsOne:model];
    }else if (2 == [model.RelType integerValue]){//model.RelType=2
        [self bannerSkipRelTypeIsTwo:model];
    }else if (3 == [model.RelType integerValue]){//新闻资讯案例
        XZNewsCaseVC *newsCaseVC = [[XZNewsCaseVC alloc]init];
        newsCaseVC.newsId = model.Id;
        [self.navigationController pushViewController:newsCaseVC animated:true];
    }else if (4 == [model.RelType integerValue]){//广告详情页面基地址
        NSString *adUrlString = [NSString stringWithFormat:@"%@/%@",URL_ADURL,model.Id];
        SFSafariViewController *sfVC = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:adUrlString]];
        sfVC.title = model.Title;
        sfVC.delegate = self;
        [self presentViewController:sfVC animated:YES completion:nil];
    }
}
/*
 *model.RelType=1 根据NormalCode  ResType IsAdded进行相应的跳转
 */
- (void)bannerSkipRelTypeIsOne:(GMTopModel *)model{
    if (0 == [model.NormalCode integerValue]) {
        [self bannerSkipNormalCodeIsZeroControllerWithBannerTopsModel:model];
    }else if (1 == [model.NormalCode integerValue]){
        [MBProgressHUD showErrorOrSuc:@"关联资源已下架或不可用" toView:self.view];
    }else if (2 == [model.NormalCode integerValue]){
        [MBProgressHUD showErrorOrSuc:@"当前手机型号非购买资源所用手机型号，你可以到“我的 - 主页 - 个人资料(付费资源管理)”模块申请变更手机型号" toView:self.view];
    }
}
/*
 *当model.NormalCode=0时 根据ResType及IsAdded进行相应的跳转
 */
- (void)bannerSkipNormalCodeIsZeroControllerWithBannerTopsModel:(GMTopModel *)model{
    if (1 == [model.ResType integerValue]) {//视频
        if (!model.IsFree) {
            GMBuyVideoVC *buyVideoVC = [[GMBuyVideoVC alloc]init];
            buyVideoVC.ResType = model.ResType;
            buyVideoVC.resId = model.Id;
          
            [self.navigationController pushViewController:buyVideoVC animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 资源 - 学习资源 - 试看(视频)“页面" toView:self.view];
        }else{
            GMPlayerViewController *playerVC = [[GMPlayerViewController alloc]init];
            playerVC.resId = model.Id;
            [self.navigationController pushViewController:playerVC animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 我的 - 我的资源 - 播放 - 问题“页面" toView:self.view];
        }
    }else if (2 == [model.ResType integerValue]){//文档
        if (!model.IsFree) {
            GMBuyFile * buyFile = [[GMBuyFile alloc]init];
            buyFile.ResType = model.ResType;
          
            buyFile.resId = model.Id;
            [self.navigationController pushViewController:buyFile animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 资源 - 学习资源 - 详情(文档)“页面" toView:self.view];
        }else{
            GMReadPDFVC *myFileVC = [[GMReadPDFVC alloc]init];
            myFileVC.resId = model.Id;
            [self.navigationController pushViewController:myFileVC animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 我的 - 我的资源 - 文档“页面" toView:self.view];
        }
    }else if (3 == [model.ResType integerValue]){//习题
        if (!model.IsFree) {
            GMBuyFile *buyFile = [[GMBuyFile alloc]init];
            buyFile.ResType = model.ResType;
            buyFile.resId = model.Id;
           
            [self.navigationController pushViewController:buyFile animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 资源 - 学习资源 - 详情(习题、试卷)“页面" toView:self.view];
        }else{
            GMExercisesVC *exercisesVC = [[GMExercisesVC alloc]init];
            exercisesVC.resId = model.Id;
            [self.navigationController pushViewController:exercisesVC animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 我的 - 我的资源 - 习题 - 答题“页面" toView:self.view];
        }
    }else if (4 == [model.ResType integerValue]){//试卷
        if (!model.IsFree) {
            GMBuyFile *buyFile = [[GMBuyFile alloc]init];
            buyFile.ResType = model.ResType;
          
            buyFile.resId = model.Id;
            [self.navigationController pushViewController:buyFile animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 资源 - 学习资源 - 详情(习题、试卷)“页面" toView:self.view];
        }else{
            GMExaminationVC * examinationVC = [[GMExaminationVC alloc]init];
            examinationVC.resId = model.Id;
            [self.navigationController pushViewController:examinationVC animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 我的 - 我的资源 - 试卷考试 - 考试须知“页面" toView:self.view];
        }
    }else if (9 == [model.ResType integerValue]){//课程包
        if (!model.IsFree) {
            GMBuyFile *buyFile = [[GMBuyFile alloc]init];
            buyFile.ResType = model.ResType;
          
            buyFile.resId = model.Id;
            [self.navigationController pushViewController:buyFile animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 资源 - 学习资源 - 详情(课程包)“页面" toView:self.view];
        }else{
            GMCoursePackageVC *coursePackageVC = [[GMCoursePackageVC alloc]init];
            coursePackageVC.resId = model.Id;
            coursePackageVC.titleStr = model.Title;
            [self.navigationController pushViewController:coursePackageVC animated:true];
            //            [MBProgressHUD showErrorOrSuc:@"跳转”主页 - 我的 - 我的资源 - 课程包“页面" toView:self.view];
        }
    }
}
/*
 *model.RelType=2 根据 IsAdded进行相应的跳转
 */
- (void)bannerSkipRelTypeIsTwo:(GMTopModel *)model{
    if (!model.IsAdded) {
        XZGroupIntroduceVC *groupIntroduceVC = [[XZGroupIntroduceVC alloc]init];
        groupIntroduceVC.titileStr = model.Title;
        groupIntroduceVC.groupId = model.Id;
        [self.navigationController pushViewController:groupIntroduceVC animated:true];
    }else{
        XZMyGroupDetailVC *myGroupDetailVC = [[XZMyGroupDetailVC alloc]init];
        myGroupDetailVC.titleStr = model.Title;
        myGroupDetailVC.groupId = model.Id;
        [self.navigationController pushViewController:myGroupDetailVC animated:true];
    }
}
/**处理页面点击事件*/
-(void)handleClickWithTypeStr:(NSString *)typeStr{
    UIViewController *controller;
    if ([typeStr isEqualToString:@"我的课件"]) {
        GMMyClassVC *classVC =[[GMMyClassVC alloc] init];
        controller = classVC;
    }else if ([typeStr isEqualToString:@"我的消息"]){
        XZMyMessageVC *messageVC = [[XZMyMessageVC alloc]init];
        controller = messageVC;
    }else if ([typeStr isEqualToString:@"我的问题"]){
        XZMyQuestionVC *questionVC = [[XZMyQuestionVC alloc]init];
        controller = questionVC;
    }else if ([typeStr isEqualToString:@"我的错题本"]){
        GMExercisesVC *mistakesVC = [[GMExercisesVC alloc]init];
        mistakesVC.fromType = @(4);
        controller = mistakesVC;
    }else if ([typeStr isEqualToString:@"我的考试"]){
        XZMyExamVC *examVC = [[XZMyExamVC alloc]init];
        controller = examVC;
    }else if ([typeStr isEqualToString:@"我的班组社团"]){
        XZMyGroupVC *groupV = [[XZMyGroupVC alloc]init];
        controller = groupV;
    }
    [self.navigationController pushViewController:controller animated:YES];
}
@end
